//
// Created by tang on 2022/10/24.
//

#include "buffer.hpp"

namespace GL
{
    Buffer::Buffer() : m_handle_(0) {
        GLCallValidation(glGenBuffers(1, &m_handle_));
    }

    Buffer::~Buffer() {
        GLCallValidation(glDeleteBuffers(1, &m_handle_));
    }

    void Buffer::Bind(GLenum target) const {
        GLCallValidation(glBindBuffer(target, m_handle_));
    }

    void Buffer::Data(GLenum target, GLsizei length, const void *data, GLenum usage) {
        if (m_handle_ != 0)
            GLCallValidation(glBufferData(target, length, data, usage));
    }

    BufferPtr Buffer::Create() {
        return std::make_shared<Buffer>();
    }

}
